﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using APILocawebGateway.HTMLHelper;
using System.Collections.Specialized;
using APILocawebGateway;
using System.Net;
using System.IO;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("TestProject")]
namespace APILocawebGateway.REDECARD
{
    internal sealed class UtilidadesREDECARD
    {
        /// <summary>
        /// Este método formata um decimal para o formato usado no formulario do REDECARD.
        /// Exemplo: 
        /// input:1,00-output:0000000100
        /// input:1,0000-output:0000000100
        /// input:10,00-output:0000001000  
        /// </summary>
        /// <param name="currency"></param>
        /// <returns></returns>
        public static string FormataMoedaParaFormREDECARD(Decimal currency)
        {
            return FormataMoeda(currency, 10);

        }

        /// <summary>
        /// Este método formata um decimal para a configuração usada na confirmação REDECARD
        /// Exemplo: 
        /// input:1,00-output:0000000000001.00
        /// input:1,0000-output:0000000000001.00
        /// input:10,00-output:0000000000010.00  
        /// </summary>
        /// <param name="currency"></param>
        /// <returns></returns>
        public static string FormataMoedaParaConfirmacaoREDECARD(Decimal currency)
        {
            String value = FormataMoeda(currency, 15);
            value = value.Insert(value.Length - 2, ".");
            return value;

        }

        private static String FormataMoeda(Decimal currency, Int32 tamanhoCampo)
        {

            String currencyasString = currency.ToString();
            if (currencyasString.Contains(","))
            {
                currencyasString = currencyasString.Remove(currencyasString.IndexOf(",") + 1);
                currencyasString += "00";
            }
            currencyasString = currencyasString.Replace(",", "").Replace(".", "");
            if (currencyasString.Length < tamanhoCampo)
                for (int i = currencyasString.Length; i < tamanhoCampo; i++)
                    currencyasString = "0" + currencyasString;

            return currencyasString;
        }

    }
}
